public with sharing class SetLocalAttendance {
   public String strTest{get;set;}
   public boolean showbutton{get;set;}
    public String idStr{   
         get{       
               return System.currentPageReference().getParameters().get('id');    
            }         
           set;}
    public String msg{get;set;}
    public List<NationalAttendee__c> AttendeeList{
    get
    {
        if(AttendeeList==null)
            AttendeeList=new List<NationalAttendee__c>();
        return AttendeeList;
    }
    set;}
    
    public List<NationalAttendee__c> getAttendee
    {
        get{
            if(AttendeeList!=null)
            {
                AttendeeList.clear();
            }
            HCPEducation__c hcpe = [Select id,date__c From HCPEducation__c Where id =: idStr];
            Date Dtoday = Date.today();
            if(Dtoday < hcpe.date__c)
            {
                msg = '填写日期未到';
                showbutton=true;
                return null;
            }
           /* else if(Dtoday > hcpe.date__c + 1)
            {
                msg = '填写日期已过';
                showbutton=true;
                return null;
            }*/
            else
            {
                msg = null;
            }
            
             for(NationalAttendee__c att:[select id,HCP__c,Hospital2__c,HCPDepartment__c,HCPadministrativetitle__c,IsAttended__c 
                                          from NationalAttendee__c where HCPEducation__c=:idStr])
           {
               AttendeeList.add(att);
           }

           return AttendeeList;
       }
       set;
    }
    
    public PageReference Save()
    {   
          
        update AttendeeList;
            list<hcpeducation__c>  hcpl=[select TotalNumberoftargetHCP__c,id,totalarrived__c from HCPEducation__c where id=:idStr ];
           if(hcpl.size()>0){
           HCPEducation__c hcp=hcpl[0];
         
           List<NationalAttendee__c> attl=[select IsAttended__c from NationalAttendee__c where IsAttended__c=:true and HCPEducation__r.id=:idStr];
           hcp.LocalActivityAttends__c=attl.size();
           if(hcp.totalarrived__c==null || hcp.totalarrived__c<attl.size()){
               hcp.totalarrived__c=attl.size();
           }
             update hcp;  
       }            
         pageReference pr = new pageReference('/'+ idStr); 
         pr.setredirect(true);        
         return pr;  
     }
     
    static testMethod void SetLocalAttendanceTest()
    {
        SetLocalAttendance testCase = new SetLocalAttendance();
        testCase.Save();       
        
        HCPEducation__c hcpe = new HCPEducation__c();
        hcpe.Name = 'a';
        hcpe.date__c = date.Today().addDays(3);
        hcpe.place__c = 'a';
        insert hcpe;
        
        test.setCurrentPageReference(Page.SetLocalAttendanceList);
        System.currentPageReference().getParameters().put('id', hcpe.Id); 

        testCase.AttendeeList = null;
        testCase.Save();
        System.assert(testCase.getAttendee == null);        
        
        
    
    }
     
}